/* const sleep = (time) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve()
    }, time)
  })
} */

const sleep = (time) => new Promise((resolve) => setTimeout(resolve, time))

;(async() => {
  console.log(1)
  // 等三秒之后打印 2，除了 setTimeout，也可以基于 Promise 编写一个睡眠函数
  await sleep(3000)
  console.log(2)
})()
